package me.firstapp.manage.apiClient;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import me.firstapp.common.json.SingleObject;
import me.firstapp.manage.common.BaseManage;
import me.firstapp.spi.system.ApiClientService;

@Controller
@RequestMapping(value = "/apiClientManage")
public class ApiClientManagePage extends BaseManage {

	@Autowired
	private ApiClientService apiClientService;

	@RequestMapping(value = "/apiClientList.html", method = RequestMethod.GET)
	public ModelAndView apiClientListView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("apiClient/apiClientList", modelMap);
	}

	@RequestMapping(value = "/apiClientAdd.html", method = RequestMethod.GET)
	public ModelAndView apiClientAddView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		return new ModelAndView("apiClient/apiClientAdd", modelMap);
	}

	@RequestMapping(value = "/apiClientUpdate.html", method = RequestMethod.GET)
	public ModelAndView apiClientUpdateView(Long id, String description, HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) {
		modelMap.put("id", id);
		modelMap.put("description", description);
		return new ModelAndView("apiClient/apiClientUpdate", modelMap);
	}

	@RequestMapping(value = "/apiClientRecordList.html", method = RequestMethod.GET)
	public ModelAndView apiClientRecordListView(Long apiClientId, HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) {
		SingleObject<Long> totalResult = apiClientService.findApiClientRecordTotalTimes(apiClientId);
		SingleObject<Long> meanResult = apiClientService.findApiClientRecordMeanTimes(apiClientId);
		modelMap.put("totalTimes", totalResult.getObject());
		modelMap.put("meanTimes", meanResult.getObject());
		modelMap.put("apiClientId", apiClientId);
		return new ModelAndView("apiClient/apiClientRecordList", modelMap);
	}
}
